package com.tyhy.enums;

/**
 * Created by xiaowei on 2020/2/29.
 * 返回码公共枚举
 */
public enum ReturnCodeEnum {
	CODE_N00000("N00000", "message.common.success"),
	CODE_E00500("E00500", "message.common.failed"),


	/**
	 * 身份认证-异常错误
	 */
	CODE_E00100("E00101", "message.auth.error"),
	/**
	 * 身份认证-参数错误
	 */
	CODE_E00101("E00101", "message.auth.param.error"),
	/**
	 * 身份认证-appId未授权
	 */
	CODE_E00102("E00101", "message.auth.unauthorized"),
	/**
	 * 身份认证-token过期
	 */
	CODE_E00103("E00101", "message.auth.token.expire"),
	/**
	 * 身份认证-token失败
	 */
	CODE_E00104("E00101", "message.auth.token.fail");


	private String code;
	private String value;

	private ReturnCodeEnum(String code, String value) {
		this.code = code;
		this.value = value;
	}

	public final String getCode() {
		return this.code;
	}

	public final String getValue() {
		return this.value;
	}


	public String toString() {
		return this.code + "=" + this.value;
	}


	/**
	 * 根据code获取枚举对象
	 *
	 * @param code
	 * @return
	 */
	public static ReturnCodeEnum getReturnEnum(String code) {
		for (ReturnCodeEnum returnCodeEnum : ReturnCodeEnum.values()) {
			if (code.equals(returnCodeEnum.getCode())) {
				return returnCodeEnum;
			}
		}
		return null;
	}
}
